package com.top.zk.pandachannel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.top.zk.pandachannel.R;
import com.top.zk.pandachannel.bean.EyeBean2;
import com.top.zk.pandachannel.help.RecyclerViewAdapterHelper;
import java.util.List;

/**
 * Created by Administrator on 2016/12/21.
 */

public class EyeRecyclerviewAdapter extends RecyclerViewAdapterHelper<EyeBean2.ListBean>{

    private static final int STATE1 = 0, STATE2 = 1;

    public EyeRecyclerviewAdapter(Context context, List<EyeBean2.ListBean> list) {
        super(context, list);
    }

    @Override
    public int getItemViewType(int position) {
        if ((list.get(position).getDatatype()).equals("video")) {
            return STATE1;
        }
        return STATE2;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case STATE1:
                view = inflater.inflate(R.layout.item1_recycleriew_eye,parent,false);
                return new ViewHolder1(view);
            case STATE2:
                view = inflater.inflate(R.layout.item2_recyclerview_eye, parent, false);
                return new ViewHolder2(view);
        }
        return null;
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder1) {
            ViewHolder1 holder1 = (ViewHolder1) holder;
            holder1.textView_eye_video.setText(list.get(position).getVideolength());
            holder1.textView_eye_title.setText(list.get(position).getTitle());

            String timeURL = list.get(position).getPicurl();

            Glide.with(context).load(timeURL)
                    .into(holder1.imageView_eye_pic);
        }else if(holder instanceof ViewHolder2){
            ViewHolder2 holder2 = (ViewHolder2) holder;
            holder2.textView_eye_title.setText(list.get(position).getTitle());

            String timeURL = list.get(position).getPicurl();

            Glide.with(context).load(timeURL)
                    .into(holder2.imageView_eye_pic);
        }
    }

    class ViewHolder1 extends RecyclerView.ViewHolder{

        private ImageView imageView_eye_pic;
        private TextView textView_eye_video;
        private TextView textView_eye_title;

        public ViewHolder1(View itemView) {
            super(itemView);
            imageView_eye_pic = (ImageView) itemView.findViewById(R.id.imageView_eye_pic);
            textView_eye_video = (TextView) itemView.findViewById(R.id.textView_eye_video);
            textView_eye_title = (TextView) itemView.findViewById(R.id.textView_eye_title);
        }
    }

    class ViewHolder2 extends RecyclerView.ViewHolder{

        private ImageView imageView_eye_pic;
        private TextView textView_eye_title;

        public ViewHolder2(View itemView) {
            super(itemView);
            imageView_eye_pic = (ImageView) itemView.findViewById(R.id.imageView_eye_pic);
            textView_eye_title = (TextView) itemView.findViewById(R.id.textView_eye_title);
        }
    }
}
